WDV221 Intro Javascript

Variables and Data Types - Homework


Please complete the following exercises on this page. When complete post the page to your WDV221 folder on the server. Make a link in your WDV221 Intro Javascript page for this assignment. Contact your instructor and demonstrate that you have completed the assignment.

Using Blackboard complete the In Class Exercise Assignment. Download your Homework project and being working on it with your remaining time.

For each exercise use a comment line to put the Exercise number within the script. Also place a short description of what the script is doing.


1. Create a runtime script on this page. In that script define four variables called color1 through color4. Assign each a color. Use a document.write to output the four colors as elements in an ordered list. Hint: Write a quick ordered list in HTML and then replace the HTML with content from your script. Use the document.write( ) to output the <li> elements. Place the list below this <p>.

2. Write a function called displayColors( ). Use alert( ) to display the values of the color1 through color4 variables. Display an alert that explains why the function works as it does. Activate this function as part of the runtime function in 1. above.

3. Create a function called nameInformation( ). Use the prompt( ) to ask the user for a name. Store that name in a local variable called inName within the function. Display the name that was entered using an alert( ). Use the String Object to determine how many characters are in the name. Display the length of the name using an alert( ). Use an onclick event handler to activate this function.

4. Create a function called displayInName( ). Display the value of the inName variable from the nameInformation( ) from 3. above. Display an alert that explains why the function works as it does. NOTE: Do not define inName in this function. You are display the variable from the nameInformation( ) function.

5. Create a function called getEmailName( ). Use a prompt to ask the user for an email address. Use methods from the String Object to display the name from the email address. For example if the user enters "jLeenan@yahoo.com" your function should display "jLeenan". Use an event handler to activate this function.

Grading:

There are five exercises on this document. Each exercise is graded seperately and totaled for the Project grade. Each exercise will be graded using the following scale.

Grade Expectation
5 Works as expected. Correctly uses concepts presented in class. Documented as needed and well formatted.
4 Works as expected. Uses some of the concepts presented in class. Lacks documentation if needed or poorly formatted/structured.
2 Produces results but not as expected OR Exercise is attempted but produces an error.
0 Does not produce any results. Fails to use any concepts presented in class or not attempted.